package com.lyy.king.common.core.domain;

import com.lyy.king.common.core.constant.HttpStatus;

import java.io.Serializable;

/**
 * 响应结果
 *
 * @param <T>
 */
public class Result<T> implements Serializable {
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public Result() {
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 响应成功
     * @return
     */
    public static Result success() {
        return new Result(HttpStatus.SUCCESS, "操作成功");
    }

    /**
     * 响应成功
     * @param code 状态码
     * @return
     */
    public static Result success(Integer code) {
        return new Result(code, "操作成功");
    }

    /**
     * 响应成功
     * @param message 消息
     * @return
     */
    public static Result succcess(String message) {
        return new Result(HttpStatus.SUCCESS, message, null);
    }

    /**
     * 响应成功
     * @param data 响应数据
     * @param <T> 响应数据类型
     * @return
     */
    public static <T> Result<T> succcess(T data) {
        return new Result(HttpStatus.SUCCESS, "操作成功", data);
    }

    /**
     * 响应成功
     * @param code 响应状态码
     * @param message 响应消息
     * @return
     */
    public static Result succcess(Integer code, String message) {
        return new Result(code, message, null);
    }

    /**
     * 响应成功
     * @param message 响应消息
     * @param data 响应数据
     * @param <T> 数据类型
     * @return
     */
    public static <T> Result<T> succcess(String message, T data) {
        return new Result(HttpStatus.SUCCESS, message, data);
    }

    /**
     * 响应失败
     * @return
     */
    public static Result error() {
        return new Result(HttpStatus.ERROR, "系统错误");
    }

    /**
     * 响应失败
     * @param message 失败消息
     * @return
     */
    public static Result error(String message) {
        return new Result(HttpStatus.ERROR, message);
    }

    /**
     * 响应失败
     * @param code 状态码
     * @param message 响应消息
     * @return
     */
    public static Result error(Integer code, String message) {
        return new Result(code, message);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
